<?php
/*
* Kusht Mud.
* ----
* The MIT License
* Copyright (c) 2010 Andrew Tutt
* ----
*/

/* Room Class
*
* This is the Game Object for a Room
*/

require_once "BaseObject.class.inc";

class Room extends BaseObject {
	public $people	= array();  			// Characters in the Room
	//public $contents 	= array();			// Objects in the Room
	//public $extra_descr; 	// ExtraDescription (a future struct) (if you want even MORE description, use a MetaText)
	public $area;							// The Area in Which the Room is Embedded (For some limited programmatic benefits)
	public $exits;							// Array of Exit Objects (unlimited)
	public $sector;							// This allows programmers to determine whether mobiles or areas have boundaries
		
	/* Set in All_Flags */
	//public $light;		// Manual Override: This room is always lit
	//public $sector_type; // Water, city street, room, etc.

	function __construct() {
		set_fields_equal($this,new BaseObject()); // Don't override the previous constructor
		$this->exits = array();
		$this->name = "A Default Room";
		$this->description = "A default room description.";
		$this->image = "alpha.jpg";  
	}	

	function has_exit($name) {
		if(get_obj_by_field_value($name,"name",$this->exits)) { return true; }
		return false;
	}

	function get_char($queryinguser, $targetstr) {
		foreach($this->people as $person) {
			if (stripos($person->name,$targetstr)!==FALSE) { return $person; }
		}
		
		return FALSE;
	}

	function add_char($user) {
		array_push($this->people,$user);
		$user->change("in_object",$this);
		$this->updatePeopleInside();
	}
	
	function rmv_char($user) {
		array_del_elem($this->people,$user);
		$user->change("was_in_object",$this);
		$this->updatePeopleInside();
	}
	
	function updatePeopleInside() {
		foreach($this->people as $person) {
			clientHandler::updatePeopleInside($person);
		}
	}
	
	function is_empty() {
		return empty($this->people);
	}
	
}

?>